How can I use TMask when the mask contains "["?

Posted by Lobuno on Stack Overflow See other posts from Stack Overflow or by Lobuno
Published on 2010-03-29T19:27:16Z Indexed on 2010/03/31 5:03 UTC
Read the original article Hit count: 434

Filed under:
|

I have been experimenting with TMask in Delphi 2010 and it seems to work as expected except in one situation: when the mask name contains [ or ] the mask always seem to return false. For example:

var
  MaskObj : TMask;
begin
  MaskObj:= TMask.Create('c:\[test]\*');
  try
    Result:= MaskObj.Matches('c:\[test]\text');
  finally
    FreeAndNil(MaskObj);
  end;
end;

returns false. ...

Yes, [ and ] are legal characters in file name. So if I want to exclude for example all files in c:[test]*, what could I do here? My only solution is to do a StringReplace if [ is detected, but this will be slow for a large number of files:

if (pos('[', Mask)>0) then
begin
  mask:= ReplaceString(Mask, '[','_', etc...
  // and do the same for the file name---
end;

Is there any other approach?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about wildcard